package day06;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class CharsetFilter implements Filter {
    private FilterConfig config;

    @Override
    public void init(FilterConfig filterConfig) {
        this.config=filterConfig;
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request= (HttpServletRequest) servletRequest;
        HttpServletResponse response= (HttpServletResponse) servletResponse;



        // request.setCharacterEncoding("utf-8");


        String encoding=config.getInitParameter("encoding");

        request.setCharacterEncoding(encoding);




        chain.doFilter(request,response);
    }

    @Override
    public void destroy() {

    }
}
